# This file is part of the Net::Tube module.
#
# Net::Tube is Free Software; you can use, redistribute it and/or
# modify it under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
#    Foundation, either version 2, or (at your opinion) any later
#    version, or
#
# b) the "Artistic License" which comes with Perl.
#
package Net::Tube::Loader::File;

use Net::Tube::Loader;
use IO::File;

our @ISA = qw(Net::Tube::Loader);

sub load {
    my $self   = shift;
    my $bucket = shift;
    my $file   = shift;

    if ( ref $file && $file->isa('XML::LibXML::Node') ) {
        $file = $file->textContent;
    }

    # read in the datafile
    if ( -f $file && -r $file ) {
        my $data = "";
        my $fh   = IO::File->new("< $file");
        if ($fh) {
            while (<$fh>) {    
                $data .= $_;
            }
            $fh->close;
        }
        $self->add_to_bucket( $bucket, $data );
    }
}

1;
